package edu.uc.service;

import java.util.HashMap;
import edu.uc.dto.User;
import edu.uc.dao.*;
/**
 * Class = UserServiceStub implements IUserService
 * 
 * @author Ckorczyk1
 *
 */
public class UserServiceStub implements IUserService{

	
	/**
	 * method logon
	 * 
	 * @param = username
	 * @param = password
	 * 
	 * @return true if username and password match and false if one or both do not match
	 */
	@Override
	public boolean logon(String username, String password) throws Exception {
		// TODO Auto-generated method stub
		
		//create new test object
		UserProviderStub test = new UserProviderStub();
		//hashmap from UserProviderStub.fetchAll
		HashMap<String, User> allUsers = test.fetchAll();
		//check if username and password exist in the hashMap
		if(allUsers.containsKey(username)) {
			User  u = allUsers.get(username);
			if(password == u.getPassword()) {
				//return true if username and password exist 
					return true;
			}
			else{
				//Return result as false if password does not match
				return false;
			}
		}
		else{
			//Return result as false if username does not match
			return false;
		}

	}
/**
 * method save
 * 
 * @param = user
 * 
 * invokes the save method from IUserDAO
 */
	@Override
	public void save(User user) throws Exception {
		// TODO Auto-generated method stub
		
		//new UserProviderStub object
		UserProviderStub correctUser = new UserProviderStub();
		//save object
		correctUser.save(user);

	}

	/**
	 * mehtod getUser
	 * @param = username
	 * 
	 * invokes the fetch method from IUserDAO
	 */
	@Override
	public User getUser(String username) throws Exception {
		// TODO Auto-generated method stub
		
		//new userProviderStub object
		UserProviderStub fetchUser = new UserProviderStub();
		
		//return fetch Object with key matching the username
		return fetchUser.fetch(username);

		//return null;
	}

}
